package com.tetris.view;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

import com.tetris.entities.Ground;
import com.tetris.entities.Shape;
import static com.tetris.util.Constants.*;
/**
 * @author 吴松 create the file at 2013-4-7 <br>
 * is com.itcast.tetris.view.GamePanel <br>
 * Des : 图形容器
 */
public class GamePanel extends JPanel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Ground ground;
	private Shape shape;
	
	//图形显示
	public void display(Ground ground,Shape shape){
		this.ground = ground;
		this.shape = shape;
		this.repaint();
	}

	//重绘图形
	@Override
	protected void paintComponent(Graphics g) {
		g.setColor(new Color(0x00f9ed));
		g.fillRect(0, 0, CELL_Size*GAME_WIDTH, 
				CELL_Size*GAME_HEIGHT);
		if(shape!=null && ground!=null){
			shape.drawShape(g);
			ground.drawShape(g);
		}
	}
	
	/**
	 * 初始化时设置窗口游戏区大小
	 */
	public GamePanel(){
		this.setSize(CELL_Size*GAME_WIDTH,
				CELL_Size*GAME_HEIGHT);
	}
}
